package com.first.nell.components.dialog

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.*
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.first.nell.R
import com.first.nell.base.BaseDialogAction
import com.first.nell.data.DataCustomizeContact
import com.first.nell.databinding.DialogFirstNellCustomerServiceBinding
import com.first.nell.me.CustomerServiceAdapter
import com.first.nell.utils.AppConfigUtil

class CustomerServiceDialog : DialogFragment(), BaseDialogAction {

    companion object {
        fun showFirstNellDialog(
            fragmentManager: FragmentManager
        ) {
            val dialog = CustomerServiceDialog()
            dialog.showNow(fragmentManager, CustomerServiceDialog::class.java.simpleName)
        }
    }

    lateinit var mFirstNellViewFirstNellBinding: DialogFirstNellCustomerServiceBinding
    lateinit var mFirstNellCustomerFirstNellServiceFirstNellAdapter: CustomerServiceAdapter

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mFirstNellViewFirstNellBinding = DialogFirstNellCustomerServiceBinding.inflate(layoutInflater)

        return mFirstNellViewFirstNellBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initFirstNellSubviews()
        dialog?.setCancelable(true)
        dialog?.setCanceledOnTouchOutside(true)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.Dialog)
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onStart() {
        super.onStart()

        dialog?.window?.let {
            it.attributes.gravity = Gravity.CENTER
            it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
//            it.setWindowAnimations(R.style.bottomDialogAnimation)
        }

        mFirstNellCustomerFirstNellServiceFirstNellAdapter.notifyDataSetChanged()
    }

    override fun initFirstNellSubviews() {
        try {
            val list = mutableListOf<DataCustomizeContact>()
            val contacts = AppConfigUtil.getCashArrwoCustomerFirstNellServiceFirstNellCnotacts()
            list.addAll(contacts)

            mFirstNellCustomerFirstNellServiceFirstNellAdapter =
                CustomerServiceAdapter(list)
            mFirstNellViewFirstNellBinding.rcDialogCustomerServiceList.layoutManager =
                LinearLayoutManager(requireContext())
            mFirstNellViewFirstNellBinding.rcDialogCustomerServiceList.adapter = mFirstNellCustomerFirstNellServiceFirstNellAdapter

            mFirstNellViewFirstNellBinding.imageDialogCustomerServiceClose.setOnClickListener { dismiss() }

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun showFirstNellWithFirstNellUIFirstNellTag(gTag: String, fragmentManager: FragmentManager) {
    }

    override fun setFirstNellOnFirstNellActionFirstNellClickFirstNellListener(listener: (Int) -> Unit) {
    }

}